package cjakma.study.portfolio.common.controller;

import java.util.Locale;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;








//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
import org.springframework.beans.TypeMismatchException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.context.MessageSourceAware;
import org.springframework.context.MessageSourceResolvable;
import org.springframework.core.Conventions;
//import org.springframework.dao.DataAccessException;
//import org.springframework.transaction.TransactionException;
import org.springframework.util.Assert;
import org.springframework.validation.BindException;
import org.springframework.validation.BindingResult;
import org.springframework.validation.DataBinder;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
//import org.springframework.web.multipart.MaxUploadSizeExceededException;
//import org.springframework.web.multipart.MultipartException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException;
import org.springframework.web.servlet.support.RequestContextUtils;
//import com.ibatis.sqlmap.client.SqlMapException;
//import org.mybatis.spring.MyBatisExceptionTranslator;
/*
import com.unus.ktPortfolio.event.vo.ResponseVO;
import com.unus.ktPortfolio.common.PortfolioResultCode;
import com.unus.ktPortfolio.common.PortfolioResultMessage;
import com.unus.ktPortfolio.common.Constants;
import com.unus.ktPortfolio.common.exception.PortfolioException;
import com.unus.ktPortfolio.common.validation.ValidationOperator;
import com.unus.ktPortfolio.common.validation.ValidationUtils;
import com.unus.ktPortfolio.common.validation.Validator;
*/








import cjakma.study.portfolio.common.Constants;
import cjakma.study.portfolio.common.PortfolioResultCode;
import cjakma.study.portfolio.common.PortfolioResultMessage;
import cjakma.study.portfolio.common.exception.PortfolioException;
import cjakma.study.portfolio.common.validation.ValidationOperator;
import cjakma.study.portfolio.common.validation.ValidationUtils;
import cjakma.study.portfolio.common.validation.Validator;
import cjakma.study.portfolio.pofol.vo.ResponseVO;

/**
 * 기본 컨트롤러. (모든 컨트롤러는 이 클래스를 상속해야한다)
 * 
 * @author 서성수
 */
public abstract class BaseController implements MessageSourceAware {
//
//	// Logger
//	protected Logger log = LoggerFactory.getLogger(this.getClass());
//
//	// Define views
//
//	/**
//	 * XML view name
//	 */
//	public final static String XML_VIEW = "xmlView";
//
//	/**
//	 * JSON view name
//	 */
//	public final static String JSON_VIEW = "jsonView";
//
	/**
	 * Uncaught exception view name
	 */
	public final static String PRO_ALERT_VIEW = "PortfolioAlert";

	/**
	 * Resource not found view name
	 */
	public final static String RESOURCE_NOT_FOUND_VIEW = "resourceNotFound";

	// Dependency injection.

	@Autowired
	protected MessageSource messageSource;
	@Autowired
	protected javax.validation.Validator validator;

	// Define setters.

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.springframework.context.MessageSourceAware#setMessageSource(org.springframework.context.MessageSource)
	 */
	public void setMessageSource(MessageSource messageSource) {
		this.messageSource = messageSource;
	}

	/**
	 * Set the validator.
	 */
	public void setValidator(javax.validation.Validator validator) {
		this.validator = validator;
	}

	// Define methods for message source.

	/**
	 * 프로퍼티 파일에 정의된 메시지를 가져 온다,
	 * 
	 * @param code
	 *            메시지 코드
	 * @return 메시지
	 */
	public String getMessage(String code) {
		return getMessage(code, null, null, null);
	}

	/**
	 * 프로퍼티 파일에 정의된 메시지를 가져 온다,
	 * 
	 * @param code
	 *            메시지 코드
	 * @param locale
	 *            로케일
	 * @return 메시지
	 */
	public String getMessage(String code, Locale locale) {
		return getMessage(code, null, null, locale);
	}

	/**
	 * 프로퍼티 파일에 정의된 메시지를 가져 온다,
	 * 
	 * @param code
	 *            메시지 코드
	 * @param args
	 *            {0} 으로 정의 된 매개변수
	 * @return 메시지
	 */
	public String getMessage(String code, Object[] args) {
		return getMessage(code, args, null, null);
	}

	/**
	 * 프로퍼티 파일에 정의된 메시지를 가져 온다,
	 * 
	 * @param code
	 *            메시지 코드
	 * @param args
	 *            {0} 으로 정의 된 매개변수
	 * @param locale
	 *            로케일
	 * @return 메시지
	 */
	public String getMessage(String code, Object[] args, Locale locale) {
		return getMessage(code, args, null, null);
	}

	/**
	 * 프로퍼티 파일에 정의된 메시지를 가져 온다,
	 * 
	 * @param code
	 *            메시지 코드
	 * @param defaultMessage
	 *            디폴트 메시지
	 * @return 메시지
	 */
	public String getMessage(String code, String defaultMessage) {
		return getMessage(code, null, defaultMessage, null);
	}

	/**
	 * 프로퍼티 파일에 정의된 메시지를 가져 온다,
	 * 
	 * @param code
	 *            메시지 코드
	 * @param defaultMessage
	 *            디폴트 메시지
	 * @param locale
	 *            로케일
	 * @return 메시지
	 */
	public String getMessage(String code, String defaultMessage, Locale locale) {
		return getMessage(code, null, defaultMessage, locale);
	}

	/**
	 * 프로퍼티 파일에 정의된 메시지를 가져 온다,
	 * 
	 * @param code
	 *            메시지 코드
	 * @param args
	 *            {0} 으로 정의 된 매개변수
	 * @param defaultMessage
	 *            디폴트 메시지
	 * @return 메시지
	 */
	public String getMessage(String code, Object[] args, String defaultMessage) {
		return getMessage(code, args, defaultMessage, null);
	}

	/**
	 * 프로퍼티 파일에 정의된 메시지를 가져 온다,
	 * 
	 * @param code
	 *            메시지 코드
	 * @param args
	 *            {0} 으로 정의 된 매개변수
	 * @param defaultMessage
	 *            디폴트 메시지
	 * @param locale
	 *            로케일
	 * @return 메시지
	 */
	public String getMessage(String code, Object[] args, String defaultMessage, Locale locale) {
		if (locale == null)
			locale = getCurrentLocale();
		return messageSource.getMessage(code, args, defaultMessage, locale);
	}

	/**
	 * 프로퍼티 파일에 정의된 메시지를 가져 온다,
	 * 
	 * @param resolvable
	 *            {@link MessageSourceResolvable}
	 * @return 메시지
	 */
	public String getMessage(MessageSourceResolvable resolvable) {
		return getMessage(resolvable, null);
	}

	/**
	 * 프로퍼티 파일에 정의된 메시지를 가져 온다,
	 * 
	 * @param resolvable
	 *            {@link MessageSourceResolvable}
	 * @param locale
	 *            로케일
	 * @return 메시지
	 */
	public String getMessage(MessageSourceResolvable resolvable, Locale locale) {
		if (locale == null)
			locale = getCurrentLocale();
		return messageSource.getMessage(resolvable, locale);
	}

	// Define validation methods.

	/**
	 * Validate.
	 * 
	 * @param target
	 *            the target object
	 * @param groups
	 *            group or list of groups targeted for validation (default to {@link javax.validation.groups.Default})
	 * @return {@link BindingResult}
	 */
	public BindingResult validate(Object target, Class<?>... groups) {
//		System.out.println("validator : " + ValidationUtils.validate(validator, target, groups));
//		return null;
		return ValidationUtils.validate(validator, target, groups);
	}

	/**
	 * Validate.
	 * 
	 * @param target
	 *            the target object
	 * @param objectName
	 *            the name of the target object
	 * @param groups
	 *            group or list of groups targeted for validation (default to {@link javax.validation.groups.Default})
	 * @return {@link BindingResult}
	 */
	public BindingResult validate(Object target, String objectName, Class<?>... groups) {
		return ValidationUtils.validate(validator, target, objectName, groups);
	}

	/**
	 * Validate.
	 * 
	 * @param target
	 *            the target object
	 * @param bindingResult
	 *            {@link BindingResult}
	 * @param groups
	 *            group or list of groups targeted for validation (default to {@link javax.validation.groups.Default})
	 * @return {@link BindingResult}
	 */
	public BindingResult validate(Object target, BindingResult bindingResult, Class<?>... groups) {
		ValidationUtils.validate(validator, target, bindingResult, groups);
		return bindingResult;
	}

	/**
	 * Validate.
	 * 
	 * @param target
	 *            the target object
	 * @param bindingResult
	 *            {@link BindingResult}
	 * @param operator
	 *            {@link ValidationOperator}
	 * @return {@link BindingResult}
	 */
	public BindingResult validate(Object target, BindingResult bindingResult, ValidationOperator operator) {
		Assert.notNull(operator, "Operator must not be null");
		operator.validate(validator, target, bindingResult);
		return bindingResult;
	}

	/**
	 * Validate.
	 * 
	 * @param <T>
	 *            the target class type
	 * @param target
	 *            the target object
	 * @param validator
	 *            {@link Validator}
	 * @return {@link BindingResult}
	 */
	public <T> BindingResult validate(T target, Validator<T> validator) throws BindException {
		return validate(target, (String) null, validator);
	}

	/**
	 * Validate.
	 * 
	 * @param <T>
	 *            the target class type
	 * @param target
	 *            the target object
	 * @param objectName
	 *            the name of the target object
	 * @param validator
	 *            {@link Validator}
	 * @return {@link BindingResult}
	 */
	public <T> BindingResult validate(T target, String objectName, Validator<T> validator) throws BindException {
		Assert.notNull(target, "Target must not be null");

		if (objectName == null) {
			objectName = Conventions.getVariableName(target);
		}
		// Create data binder and validate
		DataBinder binder = new DataBinder(target, objectName);
		return validate(target, binder.getBindingResult(), validator);
	}

	/**
	 * Validate.
	 * 
	 * @param <T>
	 *            the target class type
	 * @param target
	 *            the target object
	 * @param bindingResult
	 *            {@link BindingResult}
	 * @param validator
	 *            {@link Validator}
	 * @return {@link BindingResult}
	 */
	public <T> BindingResult validate(T target, BindingResult bindingResult, Validator<T> validator) throws BindException {
		Assert.notNull(target, "Target must not be null");
		Assert.notNull(bindingResult, "BindingResult must not be null");
		Assert.notNull(validator, "Validator must not be null");

		validator.validate(target, bindingResult);
		return bindingResult;
	}

	/**
	 * Throw if invalid.
	 * 
	 * @param bindingResult
	 *            {@link BindingResult}
	 * @return {@link BindingResult}
	 * @throws BindException
	 *             if there were any errors in the bind operation
	 */
	public BindingResult throwIfInvalid(BindingResult bindingResult) throws BindException {
		if (bindingResult.hasErrors()) {
			// 검사 종료. (fail)
			throw new BindException(bindingResult);
		}
		// 검사 종료. (success)
		return bindingResult;
	}

	/**
	 * Throw If invalid.
	 * 
	 * @param target
	 *            the target object
	 * @param groups
	 *            group or list of groups targeted for validation (default to {@link javax.validation.groups.Default})
	 * @return {@link BindingResult}
	 * @throws BindException
	 *             if there were any errors in the bind operation
	 */
	public BindingResult throwIfInvalid(Object target, Class<?>... groups) throws BindException {
		return throwIfInvalid(validate(target, groups));		
	}
	
	/**
	 * Throw If invalid.
	 * 
	 * @param target
	 *            the target object
	 * @param objectName
	 *            the name of the target object
	 * @param groups
	 *            group or list of groups targeted for validation (default to {@link javax.validation.groups.Default})
	 * @return {@link BindingResult}
	 * @throws BindException
	 *             if there were any errors in the bind operation
	 */
	public BindingResult throwIfInvalid(Object target, String objectName, Class<?>... groups) throws BindException {
		return throwIfInvalid(validate(target, objectName, groups));
	}

	/**
	 * Throw If invalid.
	 * 
	 * @param target
	 *            the target object
	 * @param bindingResult
	 *            {@link BindingResult}
	 * @param groups
	 *            group or list of groups targeted for validation (default to {@link javax.validation.groups.Default})
	 * @return {@link BindingResult}
	 * @throws BindException
	 *             if there were any errors in the bind operation
	 */
	public BindingResult throwIfInvalid(Object target, BindingResult bindingResult, Class<?>... groups) throws BindException {
		return throwIfInvalid(validate(target, bindingResult, groups));
	}

	/**
	 * Throw If invalid.
	 * 
	 * @param target
	 *            the target object
	 * @param bindingResult
	 *            {@link BindingResult}
	 * @param operator
	 *            {@link ValidationOperator}
	 * @return {@link BindingResult}
	 * @throws BindException
	 *             if there were any errors in the bind operation
	 */
	public BindingResult throwIfInvalid(Object target, BindingResult bindingResult, ValidationOperator operator) throws BindException {
		return throwIfInvalid(validate(target, bindingResult, operator));
	}

	/**
	 * Throw If invalid.
	 * 
	 * @param <T>
	 *            the target class type
	 * @param target
	 *            the target object
	 * @param validator
	 *            {@link Validator}
	 * @return {@link BindingResult}
	 * @throws BindException
	 *             if there were any errors in the bind operation
	 */
	public <T> BindingResult throwIfInvalid(T target, Validator<T> validator) throws BindException {
		return throwIfInvalid(validate(target, validator));
	}

	/**
	 * Throw If invalid.
	 * 
	 * @param <T>
	 *            the target class type
	 * @param target
	 *            the target object
	 * @param objectName
	 *            the name of the target object
	 * @param validator
	 *            {@link Validator}
	 * @return {@link BindingResult}
	 * @throws BindException
	 *             if there were any errors in the bind operation
	 */
	public <T> BindingResult throwIfInvalid(T target, String objectName, Validator<T> validator) throws BindException {
		return throwIfInvalid(validate(target, objectName, validator));
	}

	/**
	 * Throw If invalid.
	 * 
	 * @param <T>
	 *            the target class type
	 * @param target
	 *            the target object
	 * @param bindingResult
	 *            {@link BindingResult}
	 * @param validator
	 *            {@link Validator}
	 * @return {@link BindingResult}
	 * @throws BindException
	 *             if there were any errors in the bind operation
	 */
	public <T> BindingResult throwIfInvalid(T target, BindingResult bindingResult, Validator<T> validator) throws BindException {
		return throwIfInvalid(validate(target, bindingResult, validator));
	}

	// Define utility methods.

	/**
	 * Exposes the native {@link HttpServletRequest} that we're wrapping.
	 */
	public HttpServletRequest getRequest() {
		RequestAttributes ra = RequestContextHolder.currentRequestAttributes();
		if (!(ra instanceof ServletRequestAttributes)) {
			throw new IllegalStateException("Current request is not a servlet request");
		}
		return ((ServletRequestAttributes) ra).getRequest();
	}

	/**
	 * Get the current locale
	 */
	public Locale getCurrentLocale() {
		return RequestContextUtils.getLocale(getRequest());
	}

	/**
	 * Create new {@link ModelAndView} for success.
	 * 
	 * @return {@link ModelAndView}
	 */
	public ModelAndView success() {
		return result(PortfolioResultCode.SUCCESS.message());
	}

	/**
	 * Create new {@link ModelAndView} for success.
	 * 
	 * @param viewName
	 *            뷰 이름
	 * @return {@link ModelAndView}
	 */
	public ModelAndView success(String viewName) {
		ModelAndView modelAndView = success();
		modelAndView.setViewName(viewName);
		return modelAndView;
	}

	/**
	 * Create new {@link ModelAndView} for success.
	 * 
	 * @param view
	 *            뷰
	 * @return {@link ModelAndView}
	 */
	public ModelAndView success(View view) {
		ModelAndView modelAndView = success();
		modelAndView.setView(view);
		return modelAndView;
	}

	/**
	 * Create new {@link ModelAndView} for success.
	 * 
	 * @param modelName
	 *            모델 이름
	 * @param modelObject
	 *            모델 객체
	 * @return {@link ModelAndView}
	 */
	public ModelAndView success(String modelName, Object modelObject) {
		return success().addObject(modelName, modelObject);
	}

	/**
	 * Create new {@link ModelAndView} for success.
	 * 
	 * @param modelMap
	 *            모델 맵
	 * @return {@link ModelAndView}
	 */
	public ModelAndView success(Map<String, Object> modelMap) {
		return success().addAllObjects(modelMap);
	}

	/**
	 * Create new {@link ModelAndView} for success.
	 * 
	 * @param viewName
	 *            뷰 이름
	 * @param modelName
	 *            모델 이름
	 * @param modelObject
	 *            모델 객체
	 * @return {@link ModelAndView}
	 */
	public ModelAndView success(String viewName, String modelName, Object modelObject) {
		return success(viewName).addObject(modelName, modelObject);
	}

	/**
	 * Create new {@link ModelAndView} for success.
	 * 
	 * @param view
	 *            뷰
	 * @param modelName
	 *            모델 이름
	 * @param modelObject
	 *            모델 객체
	 * @return {@link ModelAndView}
	 */
	public ModelAndView success(View view, String modelName, Object modelObject) {
		return success(view).addObject(modelName, modelObject);
	}

	/**
	 * Create new {@link ModelAndView} for success.
	 * 
	 * @param viewName
	 *            뷰 이름
	 * @param modelMap
	 *            모델 맵
	 * @return {@link ModelAndView}
	 */
	public ModelAndView success(String viewName, Map<String, Object> modelMap) {
		return success(viewName).addAllObjects(modelMap);
	}

	/**
	 * Create new {@link ModelAndView} for success.
	 * 
	 * @param view
	 *            뷰
	 * @param modelMap
	 *            모델 맵
	 * @return {@link ModelAndView}
	 */
	public ModelAndView success(View view, Map<String, Object> modelMap) {
		return success(view).addAllObjects(modelMap);
	}

	/**
	 * Create new {@link ModelAndView}
	 * 
	 * @param message
	 *            {@link PortfolioResultMessage}
	 * @return {@link ModelAndView}
	 */
	public ModelAndView result(PortfolioResultMessage message) {
		Assert.notNull(message, "Message must not be null");

		PortfolioResultCode resultCode = message.getResultCode();

		ModelAndView modelAndView = new ModelAndView();
		modelAndView.addObject(Constants.RESULT_CODE_ATTRIBUTE_NAME, resultCode.value());
		modelAndView.addObject(Constants.RESULT_MESSAGE_ATTRIBUTE_NAME, getMessage(message));
		modelAndView.addAllObjects(message.getModel());

		return modelAndView;
	}

	/**
	 * Create new {@link ModelAndView}
	 * 
	 * @param viewName
	 *            뷰 이름
	 * @param message
	 *            {@link PortfolioResultMessage}
	 * @return {@link ModelAndView}
	 */
	public ModelAndView result(String viewName, PortfolioResultMessage message) {
		ModelAndView modelAndView = result(message);
		modelAndView.setViewName(viewName);
		return modelAndView;
	}

	/**
	 * Create new {@link ModelAndView}
	 * 
	 * @param view
	 *            뷰
	 * @param message
	 *            {@link PortfolioResultMessage}
	 * @return {@link ModelAndView}
	 */
	public ModelAndView result(View view, PortfolioResultMessage message) {
		ModelAndView modelAndView = result(message);
		modelAndView.setView(view);
		return modelAndView;
	}

	// Define exception handlers
	
	// PRO_EXCEPTION
	@ExceptionHandler
	public ModelAndView handlePortfolioException(PortfolioException exception, HttpServletResponse response) {
		PortfolioResultCode resultCode = exception.getResultCode();
		PortfolioResultMessage resultMessage = exception.getResultMessage();
		response.setStatus(resultCode.httpStatus().value());
		return result(PRO_ALERT_VIEW, resultMessage);
	}

	// UNKNOW_ERROR
	@ExceptionHandler
	public ModelAndView handleUnknownException(Throwable cause, HttpServletResponse response) {
		PortfolioResultCode resultCode = PortfolioResultCode.UNKNOWN_ERROR;
		PortfolioResultMessage resultMessage = resultCode.message();
		response.setStatus(resultCode.httpStatus().value());
		return result(PRO_ALERT_VIEW, resultMessage);
	}

//	// DATABASE_ERROR
//	@ExceptionHandler({ DataAccessException.class, TransactionException.class, SqlMapException.class })
//	public ModelAndView handleDatabaseException(Exception exception, HttpServletResponse response) {
//		PortfolioResultCode resultCode = PortfolioResultCode.DATABASE_ERROR;
//		PortfolioResultMessage resultMessage = resultCode.message();
//		response.setStatus(resultCode.httpStatus().value());
//		return result(PRO_ALERT_VIEW, resultMessage);
//	}

	// BIND_EXCEPTION (REQUEST_ERROR or REQUEST_PARAMETER_ERROR)
	@ExceptionHandler
	public ModelAndView handleBindException(BindException exception, Locale locale, HttpServletResponse response) {
		PortfolioResultMessage resultMessage;
		if (exception.hasGlobalErrors()) {
			resultMessage = PortfolioResultCode.REQUEST_ERROR.message().setMessage(exception.getGlobalError());
		} else if (exception.hasFieldErrors()) {
			resultMessage = PortfolioResultCode.REQUEST_PARAMETER_ERROR.message().setMessage(exception.getFieldError());
		} else {
			resultMessage = PortfolioResultCode.REQUEST_ERROR.message();
		}
		response.setStatus(resultMessage.getResultCode().httpStatus().value());
//		System.out.println("resultMessage : " + resultMessage);
//		System.out.println("resultMessage : " + resultMessage.getDefaultMessage());
//		System.out.println("resultMessage : " + resultMessage.getResultCode());
		return result(PRO_ALERT_VIEW, resultMessage);
	}

	// REQUEST_PARAMETER_ERROR
	@ExceptionHandler
	public ModelAndView handleRequestParameterException(MissingServletRequestParameterException exception, HttpServletResponse response) {
		PortfolioResultCode resultCode = PortfolioResultCode.REQUEST_PARAMETER_ERROR;
		PortfolioResultMessage resultMessage = resultCode.message().setArguments(exception.getParameterName(), exception.getParameterType());
		response.setStatus(resultCode.httpStatus().value());
		return result(PRO_ALERT_VIEW, resultMessage);
	}

	// NOT_FOUND_ERROR
	@ExceptionHandler({ TypeMismatchException.class, NoSuchRequestHandlingMethodException.class, HttpRequestMethodNotSupportedException.class })
	public ModelAndView handleNotFoundException(Exception exception, HttpServletResponse response) {
		PortfolioResultCode resultCode = PortfolioResultCode.NOT_FOUND_ERROR;
		PortfolioResultMessage resultMessage = resultCode.message();
		response.setStatus(resultCode.httpStatus().value());
		return result(RESOURCE_NOT_FOUND_VIEW, resultMessage);
	}

//	// UNAUTHORIZED_ERROR
//	@ExceptionHandler
//	public ModelAndView handleUnauthorizedException(UnauthorizedException exception, HttpServletResponse response) {
//		PortfolioResultCode resultCode = PortfolioResultCode.UNAUTHORIZED_ERROR;
//		PortfolioResultMessage resultMessage = resultCode.message();
//		response.setStatus(resultCode.httpStatus().value());
//		return result(PRO_ALERT_VIEW, resultMessage);
//	}
	
	
	
	// 2012.09.13 by sss Validaton Check Logic 변경
	public ResponseVO checkValidation(Object target, Class<?>... groups) throws BindException {
		return checkValidation(validate(target, groups));		
	}
	
	public ResponseVO checkValidation(BindingResult bindingResult) throws BindException {
		ResponseVO resV = new ResponseVO();
		PortfolioResultMessage resultMessage;
		if (bindingResult.hasErrors()) {
			// fail
			if (bindingResult.hasGlobalErrors()) {
				resultMessage = PortfolioResultCode.REQUEST_ERROR.message().setMessage(bindingResult.getGlobalError());
			} else if (bindingResult.hasFieldErrors()) {
				resultMessage = PortfolioResultCode.REQUEST_PARAMETER_ERROR.message().setMessage(bindingResult.getFieldError());
			} else {
				resultMessage = PortfolioResultCode.REQUEST_ERROR.message();
			}
//			System.out.println("resultMessage : " + resultMessage);
//			System.out.println("PortfolioResultCode.REQUEST_PARAMETER_ERROR.message().setMessage(bindingResult.getFieldError()) : " + PortfolioResultCode.REQUEST_PARAMETER_ERROR.message().setMessage(bindingResult.getFieldError()));
//			System.out.println("resultMessage : " + resultMessage.getDefaultMessage());
//			System.out.println("resultMessage : " + resultMessage.getResultCode());
			resV.setReturnCode(resultMessage.getResultCode().toString());
			resV.setReturnMsg(resultMessage.getDefaultMessage());
		}
		// finish
		return resV;
	}

}
